<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/mytag.jspf"%>

<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>订单信息</title>
<script type="text/javascript">
	$("#grid").jqGrid({
		pager:"#pager",
		url:"management/orderinfo/page",
		datatype: "json",  //请求的数据类型
	   	colNames:["门店","会员","会员手机","订单号","下单时间","金额（元）","状态","现金支付方式","操作"],
	   	colModel:[
	   		{name:"shopName",width:200},
	   		{name:"vipName",width:100},
	   		{name:"phone",width:100},
	   		{name:"orderNo",width:150},
	   		{name:"creTime",width:200},
	   		{name:"amount",width:100},
	   		{name:"stateName",width:100},
	   		{name:"cashPayWayName",width:60},
	   		{name:"ctrl",width:280,formatter:function(cellvalue, options, row){
	   			var btns = "<div class='am-btn-group am-btn-group-xs'>";
	   			btns+="<a href='management/orderinfo/detail/index/"+row.orderInfoId+"' class='am-btn am-btn-default' title='订单详情'><span class='am-icon-bars'></span> 详情</a>";
	   			btns+="<a href='management/orderinfo/schedule/index/"+row.orderInfoId+"' class='am-btn am-btn-default' title='订单进度'><span class='am-icon-bars'></span> 进度</a>";
	   			btns+="<button type='button' class='am-btn am-btn-default' data-am-modal=\"{target: '#my-alert'}\" title='评价' onclick='showmessage(\""+row.vipComment+"\")'><span class='am-icon-bars'></span> 评价</button>";
	   			if(row.state=="10I"){
	   			btns+="<button type='button' class='am-btn am-btn-default' data-am-modal=\"{target: '#my-confirm'}\" title='现金确认' onclick='chosePayState(\""+row.orderInfoId+"\")'><span class='am-icon-bars'></span> 现金确认</button>";
	   			}else{
	   				btns+="<button type='button' class='am-btn am-btn-default' data-am-modal=\"{target: '#my-confirm'}\" title='现金确认' disabled='disabled' onclick='chosePayState(\""+row.orderInfoId+"\")'><span class='am-icon-bars'></span> 现金确认</button>";
	   			}
	   			btns+="</div>";
	   			return btns;
	   		}},
	   	]
	});
	function showmessage(info){
		if(info!=null&&info!="null"){
			$("#infoId").text(info);
		}else{
			info = "用户还没有评价";
			$("#infoId").text(info);
		}
		
	}
	function chosePayState(id){
		$("#orderInfoId").val(id);
	}
	function updateState(state){
		var orderInfoId = $("#orderInfoId").val();
		var url = "management/orderinfo/updatestate/"+orderInfoId+"/"+state;
		$.ajax({
			type : 'POST',
			url : url,
			dataType : 'json',
			success : function(data) {
				layer.msg(data.msg);
				if (data.success) {
					$("#grid").jqGrid().trigger("reloadGrid"); //重新载入 
				}
			}
		});
	}
	$(function(){ 
	    $("#searchBtn").click(function(){
	        $("#grid").jqGrid('setGridParam',{ 
	            postData:$("#queryForm").serializeJson(), //发送数据
	            page:1
	        }).trigger("reloadGrid"); //重新载入 
	    }); 
	   $("#cashbtn").on('click', function() {
		      // do something
		    //  alert("现金");
		      
		       updateState("10A");
		    });
	   $("#posbtn").on('click', function() {
	      // do something
	    //   alert("POS");
	       updateState("10B");
	    });

	   $("#zfbtn").on('click', function() {
		 //  alert("支付宝");
		   updateState("10C");
	    });
	   $("#tgbtn").on('click', function() {
			 //  alert("团购");
			   updateState("10D");
		    });
	});
</script>
</head>

<body>
	<ol class="am-breadcrumb am-breadcrumb-slash am-padding" style="margin-bottom: 0px;">
		<li><a href="management/index">首页</a></li>
		<li class="am-active">订单信息</li>
	</ol>
	<div class="am-g">
		<form id="queryForm">
		<div class="am-u-md-4">
			<div class="am-input-group am-input-group-sm">
				<input type="text" name="orderNo" class="am-form-field" placeholder="请输入订单号查询"><span class="am-input-group-btn"><button class="am-btn am-btn-default" type="button" id="searchBtn">搜索</button></span>
			</div>
		</div>
		</form>
	</div>
	<div class="am-g am-padding-vertical">
		<div class="am-u-md-12"><table id="grid"></table><div id="pager"></div></div>
	</div>
	
	

</body>
</html>
